<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>气象站数据管理系统</title>
    <meta name="description" content="基于STM32的智能气象站数据采集与管理系统" />
    <meta name="keywords" content="气象站,数据采集,STM32,温湿度监测,环境监控" />
    <meta name="author" content="Weather Station Team" />
    
    <!-- Favicon -->
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
    
    <!-- 预加载关键资源 -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    
    <!-- 防止FOUC (Flash of Unstyled Content) -->
    <style>
      /* 初始加载样式 */
      #app {
        min-height: 100vh;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      }
      
      /* 加载动画 */
      .loading-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 9999;
        transition: opacity 0.3s ease;
      }
      
      .loading-spinner {
        width: 50px;
        height: 50px;
        border: 4px solid rgba(255, 255, 255, 0.3);
        border-top: 4px solid #ffffff;
        border-radius: 50%;
        animation: spin 1s linear infinite;
      }
      
      .loading-text {
        color: white;
        font-size: 16px;
        margin-top: 20px;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      }
      
      @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
      }
      
      /* 隐藏加载动画 */
      .loading-container.hidden {
        opacity: 0;
        pointer-events: none;
      }
    </style>
  </head>
  <body>
    <!-- Vue 挂载点 -->
    <div id="app"></div>
    
    <!-- 初始加载动画 -->
    <div id="loading" class="loading-container">
      <div style="text-align: center;">
        <div class="loading-spinner"></div>
        <div class="loading-text">气象站系统加载中...</div>
      </div>
    </div>
    
    <!-- Vue应用入口 -->
    <script type="module" src="/src/main.js"></script>
    
    <!-- 加载完成后隐藏加载动画 -->
    <script>
      // 确保DOM加载完成后立即执行
      document.addEventListener('DOMContentLoaded', function() {
        console.log('DOM已加载，准备移除加载动画');
        setTimeout(function() {
          const loading = document.getElementById('loading');
          if (loading) {
            console.log('找到加载动画，准备隐藏');
            loading.classList.add('hidden');
            setTimeout(function() {
              console.log('移除加载动画');
              loading.remove();
            }, 300);
          } else {
            console.log('未找到加载动画元素');
          }
        }, 100);
      });
      
      // 页面完全加载后的备用移除机制
      window.addEventListener('load', function() {
        console.log('页面完全加载完成');
        const loading = document.getElementById('loading');
        if (loading) {
          console.log('找到加载动画，准备隐藏(备用机制)');
          loading.classList.add('hidden');
          setTimeout(function() {
            console.log('移除加载动画(备用机制)');
            loading.remove();
          }, 300);
        }
      });
      
      // 错误处理
      window.addEventListener('error', function(e) {
        console.error('应用加载错误:', e.error);
      });
      
      // 未处理的Promise拒绝
      window.addEventListener('unhandledrejection', function(e) {
        console.error('未处理的Promise拒绝:', e.reason);
      });
      
      // 确保加载动画最终会被移除的安全机制
      setTimeout(function() {
        const loading = document.getElementById('loading');
        if (loading) {
          console.log('安全机制：强制移除加载动画');
          loading.remove();
        }
      }, 3000);
    </script>
  </body>
</html>